package com.press.services;

import com.press.bean.ContentBean;
import com.press.bean.TaxonomyBean;
import com.press.beanforview.VContentBean;
import com.press.mapper.ArticalTaxMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 分类页面   by cherry
 * Created by Lenovo on 2016/10/13.
 */
@Service("ArticalTaxService")
public class ArticalTaxService {
    @Resource(name="articalTaxMapper")
    private ArticalTaxMapper articalTaxMapper;
    //得到所有的分类名称
    public List<TaxonomyBean> getAllclassifyNames(){
        return articalTaxMapper.getAllclassifyNames();
    }
    //根据文章的类型，得到文章的信息
    public List<ContentBean> getContentInformation(int taxonomy_id,int nowpage,int pagenumber){
        return articalTaxMapper.getContentInformation(taxonomy_id,nowpage,pagenumber);
    }

    /**
     * 得到最新发布的文章的id和标题
     * @return
     */
    public List<ContentBean> getNewestcontent(){
        return articalTaxMapper.getNewestcontent();
    }
    public String getTitlebytaxonomyID(int taxonomy_id){
        return articalTaxMapper.getTitlebytaxonomyID(taxonomy_id);
    }
    //根据文章的分类id得到同类型的文章的数量
    public int getSameTaxContentNum(int taxonomy_id){
        return articalTaxMapper.getSameTaxContentNum(taxonomy_id);
    }

    /**
     * 该方法将List<ContentBean></>分类放入List<VContentBean>中
     * @param contents
     * @param url
     * @return
     */
    public List<VContentBean> setContentInVC(List<ContentBean> contents,String url,String taxtitle,int taxID){
        List<VContentBean> vContents=new ArrayList<>();
        for(int i=0;i<contents.size();i++){
            VContentBean vcontent=new VContentBean();
            vcontent.setAuthor(contents.get(i).getContent_author());
            vcontent.setModifiedDate(contents.get(i).getContent_modified());
            vcontent.setSummary(contents.get(i).getContent_summary());
            vcontent.setTitle(contents.get(i).getContent_title());
            vcontent.setThumbnail(contents.get(i).getContent_thumbnail());
            vcontent.setUrl(url+"/content?content_id="+contents.get(i).getContent_id());
            Map<String,String> taxonomy = new LinkedHashMap<>();
            taxonomy.put(url+"/taxonomy?tax="+taxID,taxtitle);
            vcontent.setTaxonomys(taxonomy);
            vContents.add(vcontent);
        }
        return vContents;
    }

    public ArticalTaxMapper getArticalTaxMapper() {
        return articalTaxMapper;
    }

    public void setArticalTaxMapper(ArticalTaxMapper articalTaxMapper) {
        this.articalTaxMapper = articalTaxMapper;
    }

    //获取分页文章list
    public List<ContentBean> getContentList(int page){
      return  articalTaxMapper.getContentFenYelist((page-1)*6);
    }
}
